import { useWait } from "@/hooks"

export default function (app) {
    app.directive("limitClick", {
        mounted(el, binding) {
            el.onclick = async () => {
                if (el.classList.contains("is-disabled")) return
                el.style.pointerEvents = "none"
                await useWait(5)
                const toggle = !el.classList.contains("is-disabled")
                if (toggle) el.classList.add("is-disabled")
                await useWait(binding.value || 500)
                el.style.pointerEvents = "auto"
                if (toggle) el.classList.remove("is-disabled")
            }
        }
    })
}